package com.example.demo.mapper;

import com.example.demo.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 角色 Mapper 接口
 * </p>
 *
 * @author Mr.Abel
 * @since 2024-03-27
 */
@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    @Select("SELECT ro.role_key FROM \n" +
            "users_and_role as uar,\n" +
            "role as ro\n" +
            "where\n" +
            "uar.role_id = ro.id\n" +
            "AND\n" +
            "uar.user_id = #{id}\n" +
            "AND\n" +
            "ro.flag = 0 and uar.flag = 0")
    List<String> selectUserRoleById(Integer id);

    @Select("SELECT DISTINCT pe.per_key FROM \n" +
            "users_and_role as uar,\n" +
            "role as ro,\n" +
            "role_and_permission as rap,\n" +
            "permission as pe\n" +
            "where\n" +
            "uar.role_id = ro.id\n" +
            "AND\n" +
            "ro.id = rap.role_id\n" +
            "AND\n" +
            "rap.permission_id = pe.id\n" +
            "AND\n" +
            "ro.flag = 0 and rap.flag = 0 and pe.flag = 0 and uar.flag = 0\n" +
            "AND\n" +
            "uar.user_id = #{id}")
    List<String> selectUserPermissionsById(Integer id);
}
